﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathLab.Messaging;

namespace MathLab.Parsing
{
    class ArrayScalarMultiplyParser
    {
        protected string _resultArrayName;

        protected string _firstArrayName;

        protected double _multiplier;

        public void parse(string input)
        {
            StringBuilder name = new StringBuilder();
            bool digitFlag = false;

            for (int i = 0; i < input.Length; i++)
            {
                string s = input[i].ToString();
                
                switch (s)
                {
                    case Literals.EQUALS:
                        resultArrayName = name.ToString();
                        name = new StringBuilder();
                        break;
                    case "*":
                        if (digitFlag)
                        {
                            multiplier = Convert.ToDouble(name.ToString());
                            digitFlag = false;
                            name = new StringBuilder();
                        }
                        else
                        {
                            firstArrayName = name.ToString();
                            name = new StringBuilder();
                        }
                        continue;
                    case "0":
                    case "1":
                    case "2":
                    case "3":
                    case "4":
                    case "5":
                    case "6":
                    case "7":
                    case "8":
                    case "9":
                    case "-":
                        digitFlag = true;
                        name.Append(s);
                        break;
                    default:
                        name.Append(s);
                        break;
                }
            }
            if (digitFlag)
            {
                multiplier = Convert.ToDouble(name.ToString());
            }
            else
            {
                firstArrayName = name.ToString();
            }
        }

        public string resultArrayName
        {
            get
            {
                return _resultArrayName;
            }
            set
            {
                _resultArrayName = value;
            }
        }

        public string firstArrayName
        {
            get
            {
                return _firstArrayName;
            }
            set
            {
                _firstArrayName = value;
            }
        }

        public double multiplier
        {
            get
            {
                return _multiplier;
            }
            set
            {
                _multiplier = value;
            }
        }
    }
}
